// import Cookies from 'js-cookie'

// const app = {
//   state: {
//     sidebar: {
//       opened: !+Cookies.get('sidebarStatus'),
//       withoutAnimation: false
//     },
//     device: 'desktop',
//     language: Cookies.get('language') || 'zh-cn',
//     size: Cookies.get('size') || 'medium'
//   },
//   mutations: {
//     TOGGLE_SIDEBAR: state => {
//       if (state.sidebar.opened) {
//         Cookies.set('sidebarStatus', 1)
//       } else {
//         Cookies.set('sidebarStatus', 0)
//       }
//       state.sidebar.opened = !state.sidebar.opened
//       state.sidebar.withoutAnimation = false
//     },
//     CLOSE_SIDEBAR: (state, withoutAnimation) => {
//       Cookies.set('sidebarStatus', 1)
//       state.sidebar.opened = false
//       state.sidebar.withoutAnimation = withoutAnimation
//     },
//     OPEN_SIDEBAR: (state, withoutAnimation) => {
//       Cookies.set('sidebarStatus', 0)
//       state.sidebar.opened = true
//       state.sidebar.withoutAnimation = withoutAnimation
//     },
//     TOGGLE_DEVICE: (state, device) => {
//       state.device = device
//     },
//     SET_LANGUAGE: (state, language) => {
//       state.language = language
//       Cookies.set('language', language)
//     }
//   },
//   actions: {
//     ToggleSideBar: ({ commit }) => {
//       commit('TOGGLE_SIDEBAR')
//     },
//     CloseSideBar({ commit }, { withoutAnimation }) {
//       commit('CLOSE_SIDEBAR', withoutAnimation)
//     },
//     OpenSideBar({ commit }, { withoutAnimation }) {
//       commit('OPEN_SIDEBAR', withoutAnimation)
//     },
//     ToggleDevice({ commit }, device) {
//       commit('TOGGLE_DEVICE', device)
//     },
//     setLanguage({ commit }, language) {
//       commit('SET_LANGUAGE', language)
//     }
//   }
// }

// export default app

import Cookies from 'js-cookie'
import { defineStore } from 'pinia'

const useAppStore = defineStore(
  'app',
  {
    state: () => ({
      sidebar: {
        opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
        withoutAnimation: false,
        hide: false
      },
      device: 'desktop',
      size: Cookies.get('size') || 'default',
      styleTheme: Cookies.get('styleTheme') || 'dark',
    }),
    actions: {
      toggleSideBar(withoutAnimation) {
        if (this.sidebar.hide) {
          return false;
        }
        this.sidebar.opened = !this.sidebar.opened
        this.sidebar.withoutAnimation = withoutAnimation
        if (this.sidebar.opened) {
          Cookies.set('sidebarStatus', 1)
        } else {
          Cookies.set('sidebarStatus', 0)
        }
      },
      closeSideBar({ withoutAnimation }) {
        Cookies.set('sidebarStatus', 0)
        this.sidebar.opened = false
        this.sidebar.withoutAnimation = withoutAnimation
      },
      toggleDevice(device) {
        this.device = device
      },
      setSize(size) {
        this.size = size;
        Cookies.set('size', size)
      },
      toggleSideBarHide(status) {
        this.sidebar.hide = status
      },
      changeStyleTheme (val) {
        if(val) {
          this.styleTheme = val
          Cookies.set('styleTheme', val)
        }
      }
    }
  })

export default useAppStore
